package org.maven.dependencybrowser.gui;
/**********************************************************************
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Contributors:

**********************************************************************/
import org.maven.dependencybrowser.controller.model.DuplicatesListManager;
import org.maven.dependencybrowser.model.Duplicate;

import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

public class DuplicatesTableModel implements TableModel, SelectableTableModel
{

    private DuplicatesListManager duplicatesListManager;

    public DuplicatesTableModel(DuplicatesListManager duplicatesListManager)
    {
        this.duplicatesListManager = duplicatesListManager;
    }

    public int getColumnCount()
    {
        return 2;
    }

    public int getRowCount()
    {
        return duplicatesListManager.size();
    }

    public boolean isCellEditable(int rowIndex, int columnIndex)
    {
        return false;
    }

    public Class getColumnClass(int columnIndex)
    {
        return String.class;
    }

    public Object getValueAt(int rowIndex, int columnIndex)
    {
        Duplicate duplicate = duplicatesListManager.get(rowIndex);
        switch (columnIndex)
        {
            case 0:
                return duplicate.getIdentifier();
            case 1:
                return duplicate.getVersions();
            default:
                throw new IllegalArgumentException("Column index out of bounds " + columnIndex);
        }
    }

    public void setValueAt(Object aValue, int rowIndex, int columnIndex)
    {
        throw new UnsupportedOperationException();
    }

    public String getColumnName(int columnIndex)
    {
        switch (columnIndex)
        {
            case 0:
                return "Artifact";
            case 1:
                return "Versions";
            default:
                throw new IllegalArgumentException("Column index out of bounds " + columnIndex);
        }
    }

    public void addTableModelListener(TableModelListener l)
    {
    }

    public void removeTableModelListener(TableModelListener l)
    {
    }

    public boolean isSelected(int row)
    {
        return duplicatesListManager.get(row).isSelected();
    }

}
